<?php 
header("content-Type: text/html; charset=utf-8");
date_default_timezone_set("PRC");
session_start();
define('DEC', DIRECTORY_SEPARATOR);// 系统分隔符
define("SYSTEM_ROOT", __DIR__ . DEC);//引入目录
define("ROOT", str_replace(strrchr(__DIR__, DEC), '', __DIR__) . DEC);//根目录
define("PUBLICROOT",ROOT . 'public'  . DEC);//运行根目录
define("TEMPLATE_ROOT", ROOT . "/public/template".DEC);//模板目录
define("LOGINTEMPLATE_ROOT", ROOT . "/public/ltemplate".DEC);//登录模板
define('ROOT_CLASS',SYSTEM_ROOT.'class'.DEC);//class库目录
define('PLUGIN_ROOT', ROOT.'plugins/');

include SYSTEM_ROOT .'define.php';//常量模块目录
if(errorstatus){
    register_shutdown_function(function(){
        echo '错误：';
        print_R(error_get_last());
    });
}


require_once SYSTEM_ROOT . 'config.php';
require_once ROOT_CLASS . "Autoloader.php";//自动载入库
Autoloader::register();
use lib\Tips;
$dsn = 'mysql:host='.dbconfig['host'].';port='.dbconfig['port'].';dbname='.dbconfig['dbname'].';charset=utf8';
try {
	$DB=new PDO($dsn,dbconfig['user'],dbconfig['pwd']);
} catch(Exception $e) {
    Tips::error('数据库连接错误，请检查 config.php 文件' , '数据库连接错误');
}


$query = $DB->query('show tables');
if (!$query) {
    $errorInfo = $DB->errorInfo();
    Tips::error('数据库查询错误：请确认您是否正确配置数据库' ,'数据库查询错误');
}
$allDb = $query->fetchAll(PDO::FETCH_ASSOC);
if (empty($allDb)) {
    Tips::error('数据库为空，请重新安装！','数据库为空','/install/');
}

require_once SYSTEM_ROOT . "360_Safe/360webscan.php";
require_once SYSTEM_ROOT."360_Safe/xss.php"; //防xss注入

require_once ROOT_CLASS . "Template.Class.php";//公共模板函数
require_once ROOT_CLASS .'Function.Class.php';//公共函数库
require_once ROOT_CLASS . "Pay_function.php"; //支付处理库
require_once ROOT_CLASS . "Cache.Class.php"; //config 库
$CACHE = new CACHE();
$conf = $CACHE->pre_fetch();//禁止直接打印否则boom
if (phpversion() < "7.99" || phpversion() > "9.0") {
	Tips::error("当前PHP版本(" . phpversion() . "),请切换到8.+方可使用!","站点提示信息");
}
$password_hash='!@#%!s!0';

$date = date("Y-m-d H:i:s");

if(!function_exists("is_https")){
	function is_https() {
		if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443){
			return true;
		}elseif(isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == '1')){
			return true;
		}elseif(isset($_SERVER['HTTP_X_CLIENT_SCHEME']) && $_SERVER['HTTP_X_CLIENT_SCHEME'] == 'https'){
			return true;
		}elseif(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
			return true;
		}elseif(isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https'){
			return true;
		}elseif(isset($_SERVER['HTTP_EWS_CUSTOME_SCHEME']) && $_SERVER['HTTP_EWS_CUSTOME_SCHEME'] == 'https'){
			return true;
		}
		return false;
	}
}

$httphost= (is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/';

$siteurl= (is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/';
define('SYS_KEY', $conf['syskey']);
if(!$conf['localurl'])$conf['localurl'] = $siteurl;
$conf['kfqq'] = $conf['qq'];

require_once ROOT_CLASS .'login.class.php'; //登录核验库
require_once ROOT_CLASS .'Notify_function.php'; // 异步回调公共函数

$salt =  randpw(6,'ALL');
require_once ROOT.'build.php';


if ($conf["version"] != Version && $update == null) {
    Tips::success('检测到有新版本 正在跳转更新' , '新版本更新','/Install/update.php');
}
gc_collect_cycles();

?>